from langchain_chroma import Chroma
from langchain_community.document_loaders import TextLoader
from langchain_text_splitters import CharacterTextSplitter

from base import embeddings

docs = (TextLoader("./store/redis_util/RedisUtil.text",encoding="UTF-8")
        .load())

#3. 使用 Chroma 构建向量库 并把向量库存储到 指定目录
vector_store_dir = "store/redis_util"
textSplitter = CharacterTextSplitter(chunk_size=1000,chunk_overlap=300)
splitDocs = textSplitter.split_documents(docs)
#pip install chromadb
Chroma.from_documents(
    splitDocs,
    embedding= embeddings,
    #指定向量数据库存储目录
    persist_directory=vector_store_dir
)